package com.lagou.edu.utils;

import com.lagou.edu.anno.Autowired;
import com.lagou.edu.anno.Component;

import java.sql.SQLException;

/**
 * 事务管理
 * @author wsz
 * @date 2021/10/18 19:41
 **/
@Component
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void beginTransaction() {
        try {
            connectionUtils.getCurrentConnection().setAutoCommit(false);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void commit() {
        try {
            connectionUtils.getCurrentConnection().commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void rollback() {
        try {
            connectionUtils.getCurrentConnection().rollback();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
